package com.ruoyi.client.fxiaoke.beans.args;

import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * crm基础查询参数对象
 * @author 官宇
 * @date 2020-05-23
 */
@Data
public class CrmQueryV2Arg extends BaseArg {
    private String currentOpenUserId;

    private Datas data = new Datas();

    public CrmQueryV2Arg(String currentOpenUserId, String apiName) {
        this.currentOpenUserId = currentOpenUserId;
        this.data.setDataObjectApiName(apiName);
    }
    
    public CrmQueryV2Arg(String currentOpenUserId) {
        this.currentOpenUserId = currentOpenUserId;
    }
    
    public void addFilter(String field,Object value,String operator) {
    	Filter filter = new Filter();
		filter.setField_name(field);
		List<Object> values = new ArrayList<>();
		values.add(value);
		filter.setField_values(values);
		filter.setOperator(operator);
		this.data.search_query_info.filters.add(filter);
    }
    
    public void addFilters(String field,List<Object> values,String operator) {
    	Filter filter = new Filter();
		filter.setField_name(field);
		filter.setField_values(values);
		filter.setOperator(operator);
		this.data.search_query_info.filters.add(filter);
    }
    

    @Data
    public static class Datas {
        private String dataObjectApiName;
        
        private String defineType;

        private String searchTemplateId;
        
        private String objectDataId;

        private SearchQueryInfo search_query_info = new SearchQueryInfo();

    }

    @Data
    public static class SearchQueryInfo{
        //偏移量
        private int offset = 0;

        private int limit = 100;

        private List<String> fieldProjection = new ArrayList<>();

        private List<Filter> filters = new ArrayList<>();

        private List<Orders> orders = new ArrayList<>();
        
        
    }

    @Data
    public static class Filter{
        private String field_name;

        private List<Object> field_values;

        private String operator;
    }

    @Data
    public static class Orders{
        private String fieldName;

        private Boolean isAsc;
    }
}
